//
//  WPNewsPreheatTableViewCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/3/31.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPNewsPreheatTableViewCell.h"
@interface WPNewsPreheatTableViewCell ()
@property (nonatomic, strong) UIView * backView;/**< 背景图 */
@property (nonatomic, strong) UIImageView * posterImageView;/**< 海报图 */
@property (nonatomic, strong) UILabel * titleLabel;/**< 标题 */
@property (nonatomic, strong) UILabel * detailLabel;/**< 详情 */
@property (nonatomic, strong) UITextField * attentionCountTextField;/**< 关注人数 */
@property (nonatomic, strong) UITextField * daysTextField;/**< 剩余天数 */
@property (nonatomic, strong) UITextField * attentionTextField;/**< 关注人数说明 */
@property (nonatomic, strong) UITextField * leftDaysTextField;/**< 剩余天数说明 */
@property (nonatomic, strong) UIButton * addAttentionBtn;/**< 添加关注 */
- (void)initializeAppearance;/**< 一般界面初始化 */
@end
@implementation WPNewsPreheatTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initializeAppearance];
    }
    return self;
}
#pragma mark - init
- (void)initializeAppearance {
    [self addSubview:self.backView];
    [self.backView addSubview:self.posterImageView];
    [self.backView addSubview:self.titleLabel];
    [self.backView addSubview:self.detailLabel];
    [self.backView addSubview:self.attentionCountTextField];
    [self.backView addSubview:self.daysTextField];
    [self.backView addSubview:self.attentionTextField];
    [self.backView addSubview:self.leftDaysTextField];
    [self.backView addSubview:self.addAttentionBtn];
}
#pragma mark - responds events
- (void)respondsToAttention:(UIButton *)sender {
    sender.selected = !sender.selected;
}
- (void)respondsToAddAttention:(UIButton *)sender {
    sender.selected = !sender.selected;
}
#pragma mark - private methods
- (void)setModelWithModel:(WPNewsPreheatModel *)model {
    _posterImageView.image = IMAGE_NAME(model.posterImageName);
    _titleLabel.text = model.title;
    _detailLabel.text = model.detail;
    _attentionCountTextField.text = model.attentionCount;
    _daysTextField.text = model.leftDays;
}
#pragma mark - getter
- (UIView *)backView {
    if (!_backView) {
        _backView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 300*DHFlexibleHorizontalMutiplier(), 280*DHFlexibleHorizontalMutiplier())];
            view.layer.borderWidth = 1;
            view.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view.layer.borderColor = COLOR_RGB(224, 224, 224, 1).CGColor;
            view;
        });
    }
    return _backView;
}
- (UIImageView *)posterImageView {
    if (!_posterImageView) {
        _posterImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300*DHFlexibleHorizontalMutiplier(), 158*DHFlexibleHorizontalMutiplier())];
            view;
        });
    }
    return _posterImageView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.posterImageView.frame)+5*DHFlexibleHorizontalMutiplier(), 300*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:16*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(58, 58, 58, 1);
            lab;
        });
    }
    return _titleLabel;
}
- (UILabel *)detailLabel {
    if (!_detailLabel) {
        _detailLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), 300*DHFlexibleHorizontalMutiplier(), 50*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.numberOfLines = 2;
            lab.textColor = COLOR_RGB(158, 158, 158, 1);
            lab;
        });
    }
    return _detailLabel;
}
- (UITextField *)attentionCountTextField {
    if (!_attentionCountTextField) {
        _attentionCountTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.detailLabel.frame), 70*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.rightViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 15, 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"人";
            lab.textColor = COLOR_RGB(141, 141, 141, 1);
            text.rightView = lab;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(234, 27, 47, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _attentionCountTextField;
}
- (UITextField *)daysTextField {
    if (!_daysTextField) {
        _daysTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(50*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.detailLabel.frame), 110*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.rightViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 15*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"天";
            lab.textColor = COLOR_RGB(141, 141, 141, 1);
            text.rightView = lab;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(234, 27, 47, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _daysTextField;
}
- (UITextField *)attentionTextField {
    if (!_attentionTextField) {
        _attentionTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(20*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.attentionCountTextField.frame), 50*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(0, 0, 13*DHFlexibleHorizontalMutiplier(), 12*DHFlexibleHorizontalMutiplier());
            [btn setImage:IMAGE_NAME(@"多边形-1-拷贝.png") forState:UIControlStateNormal];
            [btn setImage:IMAGE_NAME(@"多边形-1.png") forState:UIControlStateSelected];
            [btn addTarget:self action:@selector(respondsToAttention:) forControlEvents:UIControlEventTouchUpInside];
            text.leftView = btn;
            text.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(51, 51, 51, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text.text = @"关注";
            text;
        });
    }
    return _attentionTextField;
}
- (UITextField *)leftDaysTextField {
    if (!_leftDaysTextField) {
        _leftDaysTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(110*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.attentionCountTextField.frame), 70*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(0, 9*DHFlexibleHorizontalMutiplier(), 13*DHFlexibleHorizontalMutiplier(), 12*DHFlexibleHorizontalMutiplier());
            [btn setImage:IMAGE_NAME(@"leftDays.png") forState:UIControlStateNormal];
            text.leftView = btn;
            text.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(77, 76, 77, 1);
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text.text = @"剩余时间";
            text;
        });
    }
    return _leftDaysTextField;
}
- (UIButton *)addAttentionBtn {
    if (!_addAttentionBtn) {
        _addAttentionBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(270*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.daysTextField.frame), 17*DHFlexibleHorizontalMutiplier(), 17*DHFlexibleHorizontalMutiplier());
            [btn addTarget:self action:@selector(respondsToAddAttention:) forControlEvents:UIControlEventTouchUpInside];
            [btn setImage:IMAGE_NAME(@"iconfont-guanzhu-(3).png") forState:UIControlStateNormal];
            [btn setImage:IMAGE_NAME(@"加关注.png") forState:UIControlStateSelected];
            btn;
        });
    }
    return _addAttentionBtn;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
